package com.notice.ui;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CourseAdapter extends BaseAdapter{

	private List<HashMap<String,String>> courseList;
	private Context context;
	private LayoutInflater inflater = null;
	private static final String KEYCLASS = "key_class";
	private static final String KEYCOURSE = "key_course";
	
	public CourseAdapter (Context context, List<HashMap<String,String>> courseList) {
		this.courseList = courseList;
		this.context = context;
		inflater = LayoutInflater.from(context);
	}
	@Override
	public int getCount() {
		return courseList.size();
	}

	@Override
	public Object getItem(int position) {
		return courseList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if(convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.course_item, null);
			holder.tv_class = (TextView) convertView.findViewById(R.id.tv_class);
			holder.tv_coursename = (TextView) convertView.findViewById(R.id.tv_course);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.tv_coursename.setText(courseList.get(position).get(KEYCOURSE));
		holder.tv_class.setText(courseList.get(position).get(KEYCLASS));
		return convertView;
	}
	
	class ViewHolder {
		public TextView tv_coursename;
		public TextView tv_class;
	}
}
